package com.willian.flutterapp.activity;

//import android.app.Activity;
//import android.os.Bundle;
//
//import io.flutter.embedding.android.FlutterActivity;
//import io.flutter.embedding.engine.plugins.PluginRegistry;
//import io.flutter.plugin.common.EventChannel;
//import io.flutter.plugin.common.MethodCall;
//import io.flutter.plugin.common.MethodChannel;
//import io.flutter.plugins.GeneratedPluginRegistrant;
//
//public class MainActivity extends FlutterActivity {
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        GeneratedPluginRegistrant.registerWith(this);
//        MyFlutterPlugin.registerWith(this);
//
//        MyFlutterEventPlugin eventPlugin = MyFlutterEventPlugin.registerWith(this);
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                int counter = 0;
//                while (true){
//                    try {
//                        if (eventPlugin.eventSink != null) {
//                            eventPlugin.eventSink.success(counter++);
//                        }
//                        Thread.sleep(1000);
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                        eventPlugin.eventSink.error("计时器异常","计时器异常",e.getMessage());
//                    }
//                }
//            }
//        }).start();
//    }
//}
//
//class MyFlutterPlugin implements MethodChannel.MethodCallHandler {
//    private final Activity activity;
//    public MyFlutterPlugin(Activity activity) {
//        this.activity = activity;
//    }
//    @Override
//    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
//        if (methodCall.method.equals("getUser")) {
//            Integer userId = methodCall.argument("userId");
//            String mockUser = String.format("{\"name\":\"Wiki\",\"id\":%s}", userId);
//            result.success(mockUser);
//        }
//    }
//    public static void registerWith(PluginRegistry registry) {
//        String CHANNEL = "com.example.flutter_app/plugin";
//        PluginRegistry.Registrar registrar = registry.registrarFor(CHANNEL);
//        MethodChannel methodChannel = new MethodChannel(registrar.messenger(), CHANNEL);
//        MyFlutterPlugin myFlutterPlugin = new MyFlutterPlugin(registrar.activity());
//        methodChannel.setMethodCallHandler(myFlutterPlugin);
//    }
//}
//
//class MyFlutterEventPlugin implements EventChannel.StreamHandler {
//    public EventChannel.EventSink eventSink;
//
//    public static MyFlutterEventPlugin registerWith(PluginRegistry registry) {
//        String CHANNEL = "com.example.flutter_app/event_plugin";
//        PluginRegistry.Registrar registrar = registry.registrarFor(CHANNEL);
//        EventChannel eventChannel = new EventChannel(registrar.messenger(), CHANNEL);
//        MyFlutterEventPlugin myFlutterEventPlugin = new MyFlutterEventPlugin();
//        eventChannel.setStreamHandler(myFlutterEventPlugin);
//        return myFlutterEventPlugin;
//    }
//    @Override
//    public void onListen(Object o, EventChannel.EventSink eventSink) {
//        this.eventSink = eventSink;
//    }
//    @Override
//    public void onCancel(Object o) {
//
//    }
//}



import android.os.Bundle;
import android.util.Log;

import com.willian.flutterapp.flutterplugin.FlutterPluginCounter;
import com.willian.flutterapp.flutterplugin.FlutterPluginJumpToAct;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;

import io.flutter.plugins.GeneratedPluginRegistrant;


public class MainActivity extends FlutterActivity {

    FlutterPluginCounter pluginCounter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public void configureFlutterEngine(FlutterEngine flutterEngine){

        GeneratedPluginRegistrant.registerWith(flutterEngine);

        //给当前页面注册组件
        FlutterPluginJumpToAct.registerWith(flutterEngine, this);

        //this.pluginCounter = FlutterPluginCounter.registerWith(flutterEngine, this);
    }
}


